﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HFController;
using System.Web.SessionState;
using System.Web.Script.Serialization;
using HFController.Public;
namespace HFWebApp.AjaxSource
{
    /// <summary>
    /// LawyerModify 的摘要说明
    /// </summary>
    public class LawyerModify : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            BagePages bp = new BagePages();
            context.Response.ContentType = "text/plain";
            string action = bp.GetAll("action");
            HFModel.ResultModel result = new HFModel.ResultModel();
            switch (action)
            { 
                case "1"://修改密码
                    string oldpwd = bp.GetAll("oldpwd");
                    string newpwd = bp.GetAll("newpwd");
                    result = LawyerController.getController().doModifyLawyerPWD(oldpwd, newpwd);
                    break;
                case "2"://修改资料
                    modifyinfo(context ,bp);
                    break;
                case "3"://修改专长领域
                    result = LawyerController.getController().doModifyLawyerAreas(bp.GetAll("areas").Replace("|" ,","));
                    break;
            }
            context.Response.Write(this.getJSONResult(result));
            context.Response.End();
        }

        private void modifyinfo(HttpContext context ,BagePages bp)
        {
            System.Web.HttpPostedFile fileUpload2 = context.Request.Files["Files"];
            HTMLUPFileClass upFile = new HTMLUPFileClass();
            upFile.FileRenameMethod = 1;
            string PicTitle = "";
            if (upFile.HTMLUpLoad(fileUpload2))
            {
                PicTitle = upFile.FilePath;
            }
            string realname = bp.GetAll("reanname");
            string sex = bp.GetAll("sex");
            string bd_y = bp.GetAll("bd_y");
            string bd_m = bp.GetAll("bd_m");
            string bd_d = bp.GetAll("bd_d");
            string email = bp.GetAll("email");
            string phone = bp.GetAll("phone");
            string mobile = bp.GetAll("mobile");
            string provinceid = bp.GetAll("provinceid");
            string cityid = bp.GetAll("cityid");
            string address = bp.GetAll("address");
            string post = bp.GetAll("post");
            string fax = bp.GetAll("fax");
            string website = bp.GetAll("website");
            string lawyerno = bp.GetAll("lawyerno");
            string lawyerfirm = bp.GetAll("lawyerfirm");
            string language = bp.GetAll("language");
            string content = bp.GetAll("content");

            HFModel.ResultModel result = LawyerController.getController().doModifyLawyer(int.Parse(provinceid), int.Parse(cityid), int.Parse(sex), bd_y, bd_m, bd_d, email, phone, mobile, address, fax, post, website, realname, language, content, lawyerno, lawyerfirm, PicTitle);
            if (result.isTrue)
            {
                context.Response.Write("<script>alert('" + result.Message + "');location='/lawyeruser/lc_ModifyInfo.aspx'</script>");
            }
            else {
                context.Response.Write("<script>alert('" + result.Message + "');");
            }
        }

        protected string getJSONResult(HFModel.ResultModel result)
        {
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer(new SimpleTypeResolver());
            return jsSerializer.Serialize(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}